
var WindLogger = new Object();

/* Logger Model */

WindLoggerModel = function() {
	this.entries = new Array();
}

WindLoggerModel.prototype.getEntries = function() {
	return this.entries;
}

WindLoggerModel.prototype.addEntry = function(entryModel) {
	this.entries[this.entries.length] = entryModel;
}

WindLoggerModel.prototype.clearEntries = function() {
	this.entries.length = 0;
}

WindLoggerModel.prototype.getNumberOfEntries = function() {
	var numberOfEntries = this.getEntries().length;
	return numberOfEntries;
}

WindLoggerModel.prototype.getEntryAtIndex = function(index) {
	return this.entries[index];
}

/* Logger Entry Model */

WindLoggerEntryModel = function() {
}

WindLoggerEntryModel.prototype.setMessage = function(message) {
	this.message = message;
}

WindLoggerEntryModel.prototype.getMessage = function() {
	return this.message;
}

/* Logger View */

var WindLogger = function() {
	
}

WindLogger.createView = function(loggerModel) {
	if(loggerModel==null) {
		loggerModel = new WindLoggerModel();
	}
	
	var loggerView = new WindView();	
	loggerView.setCssClass("WindLogger");
	loggerView.setX(1000);
	loggerView.setY(100);
	loggerView.setWidth(200);
	loggerView.setHeight(200);
	
	loggerView.setModel(loggerModel);
	
	var entries = loggerModel.getEntries();
	for(var i=0; i<entries.length; i++) {
		var entryModel = entries[i];
		var entryView = WindLogger.createEntryView(entryModel);
		loggerView.add(entryView);
	}
	
	return loggerView;
}

WindLogger.createEntryView = function(entryModel) {
	var entryView = new WindView();
	entryView.setCssClass("WindLoggerEntry");
	entryView.setText(entryModel.getMessage());
	return entryView;
}

WindLogger.init = function() {
	var loggerView = WindLogger.createView();
	loggerView.setId("WindLogger");
	WindWindow.addView(loggerView);
}

WindLogger.log = function(message) {
	var view = WindWindow.getViewById("WindLogger");
	if(view!=null) {
		var model = view.getModel();
		
		var entryModel = new WindLoggerEntryModel();
		entryModel.setMessage(message);		
		model.addEntry(entryModel);
		
		var entryView = WindLogger.createEntryView(entryModel);
		view.addView(entryView);
	}
}

